package com.cote.douhahou.pretloan.setting;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.cote.douhahou.pretloan.launcher.LoginActivity;
import com.cote.douhahou.pretloan.network.HttpHelper;
import com.cote.douhahou.pretloan.utils.AkomapaLendUtil;
import com.cote.douhahou.pretloan.R;


public class LogAkomapalendoutDialog extends Dialog {

    private final String page_akomapalend = "DIALOG_LOGOUT";

    public LogAkomapalendoutDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_log_out);

        getWindow().setBackgroundDrawableResource(R.color.transparent);
        setCanceledOnTouchOutside(true);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        initView_akomapalend();
    }

    @SuppressLint("SetTextI18n")
    private void initView_akomapalend(){

        findViewById(R.id.dlo_tv_cancel).setOnClickListener(v -> {
            HttpHelper.inst().submitEvent(page_akomapalend,"CANCEL_CLICK","");
            dismiss();
        });

        findViewById(R.id.dlo_tv_logout).setOnClickListener(v -> {

            HttpHelper.inst().submitEvent(page_akomapalend,"LOGOUT_CLICK","");

            AkomapaLendUtil.clearSp();
            AkomapaLendUtil.clearState();

            dismiss();

            Intent intent = new Intent(getContext(), LoginActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            getContext().startActivity(intent);

        });

    }

    @Override
    public void show() {
        super.show();
        HttpHelper.inst().submitEvent(page_akomapalend,"START","");
    }

    @Override
    public void dismiss() {
        super.dismiss();
        HttpHelper.inst().submitEvent(page_akomapalend,"END","");

    }

}
